package Indexserver.Utils;
 


public class documentID {
	public static final long GIOI_HAN =  Long.valueOf("4294967296");
	public static long toDID(long sID, long pID){
//		String aa= Long.toBinaryString(a);
		if (sID >= GIOI_HAN || pID >= GIOI_HAN){ 
			System.out.println("Vuot qua gioi han ");
		}
		sID = sID << 32;
//		System.out.println(aa+b);
		return sID + pID;
	}
	public static sIDpID toSIDPID(long did){
		long pID = did & (GIOI_HAN - 1);
		long sID = (did >>32)& (GIOI_HAN - 1);
		return new sIDpID(sID,pID);
	}
	public static byte[] long2ByteArray(long did){		
		byte[] re = new byte[8];
		for (int i=0;i<8;i++){
			re[7-i]= (byte)(did >> (i*8));
//			System.out.println(re[i]);
		}
		return re;
	}
	public static long byteArray2Long(byte[] b){		
		long tong=0;
		int tam;
		for (int i=0;i<8;i++){	
			if (b[i]<0){
				tam = (b[i]-Byte.MIN_VALUE+1)+ Byte.MAX_VALUE;
			}else{
				tam =b[i];
			}
			tong+= (tam) * Math.pow(256,7-i);
		}
		return tong;
	}

	public static void main(String[] args) {
		//Vi du ve vuot qua gioi han
//		asso(0, Long.valueOf("4294967296"));	
//		asso(1, Long.valueOf("0"));	
//		476741369967
		/////////////////
//		long t= toDID(111, Long.valueOf("111"));	
//		sIDpID tt = toSIDPID(t);
//		System.out.println(t);
//		System.out.println(tt.sID+"  "+ tt.pID);
//		byte b[] = long2ByteArray(t);
//		long tong = byteArray2Long(b);
//		System.out.println("tong="+tong);
		//////////
//		dIDtoHTMLFile("176093659177", "");
		sIDpID sidpid = toSIDPID(Long.valueOf("60129678885"));
		String fname=Squid.prepare(Constant.CORPUS, sidpid.sID, sidpid.pID);
		System.out.println(fname);
	}
}

